/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
int colors[1000] = { 0 };

class Solution {
public:
	void initArray(int* ptr)
	{
		memset(ptr, 0, sizeof(colors));
	}
	void _numColor(TreeNode* root)
	{
		if (root == nullptr)
			return;
		colors[root->val - 1]++;
		_numColor(root->left);
		_numColor(root->right);
	}
	int numColor(TreeNode* root) {
		initArray(colors);
		_numColor(root);
		int count = 0;
		for (int i = 0; i < 1000; i++)
		{
			if (colors[i] > 0)
				count++;
		}
		return count;
	}
};